$(function(){
	promo ()
	function promo (){
		documentScroll ()
		var ii = 1
		var promo = $('.promo');
		var leng = $('.promo .promo_li').length;
		var promoFist = promo.find('.promo_li').eq(0).prop("outerHTML");
		var promoLast = promo.find('.promo_li').eq(leng-1).prop("outerHTML");
		promo.find('.promo_lis').prepend(promoLast);
		promo.find('.promo_lis').append(promoFist);
//		var promo_btns = '<div class="promo_btns">';
		var promo_btns = '<div class="promo_btn pre"></div>';
		promo_btns += '<div class="promo_btn next"></div>';
//		promo_btns += '</div>';
		var promo_pagination = '<div class="promo_pagination">';
		for(var i = 1; i <= leng; i++){
			if(i ===1){
				promo_pagination += '<div class="lis selected"></div>';
			}else{
				promo_pagination += '<div class="lis"></div>';
			}
		}
		promo_pagination += '</div>';
		promo.append(promo_pagination)
		promo.append(promo_btns)
			
		leng = leng + 2
		promo.find('.promo_lis').width(100 * leng + '%')
		promo.find('.promo_li').width(100 / leng + '%')
		var timer = setInterval(function(){
			ii++;
			promoanimate()
		},5000)
		
		function promoanimate () {
			promo.find('.promo_lis').stop().animate({'margin-left': - (100 * ii) + '%'},500);
			ii = ( ii === leng - 1) ? 1 : ii
			ii = (ii === 0) ? leng - 2 : ii
			setTimeout(function(){
				$('.promo_pagination .lis').eq(ii-1).addClass('selected').siblings().removeClass('selected')	
				promo.find('.promo_lis').stop().css({'margin-left': - (100 * ii) + '%'});
			},500)
		}
		$('.promo_btn.pre').click(function (){
			ii--;
			promoanimate()
		});
		$('.promo_btn.next').click(function (){
			ii++;
			promoanimate()
		});
		$('.promo_pagination .lis').click(function (){
			ii = $(this).index() + 1 
			promoanimate()
		});
		$('.promo').hover(function(){
			var index = $(this).index()
			clearInterval(timer)
		},function(){
			timer = setInterval(function(){
				ii++;
				promoanimate()
			},5000)
		});
	}
	
	$('.fixed_take_up').click(function(){
		$('.fixed_left').stop().animate({'height':0},500);
	})
	$(document).scroll(function(){
		documentScroll ()
	})
	$('#scrollTop').click(function(){
		$('html,body').animate({scrollTop: '0px'}, 300);
	})
	function documentScroll (){
		if($(document).scrollTop() > 800){
			$('.fixed').show();
		}else{
			$('.fixed').hide();
		}
	}
})

function showloading(){
	var loading ='<div id="loading"><div class="in"></div></div>'
	if(!$('#loading').length){
		$('body').append(loading);
		$('html,body').css('overflow','hidden')
	}
}
function hideloading(){
	$('#loading').remove()
		$('html,body').css('overflow','auto')
}